/**
 * @Description: 新手上路视频列表
 * @Author: kanglin
 * @Date: 2017/8/23
 * @Copyright: Created by Panxsoft.
 */


;function initNoviceVideo() {
    Vue.use(window.ELEMENT.Pagination);
    new Vue({
        el: '#video',
        data: function () {
            return {
                videos: [],
                total:0,
                from:0,
                to:0,
                per_page:8,
                current_page:1,
                last_page:0,
            }
        },
        methods: {
            /**
             *  获取视频列表
             *  @return {undefined}
             */
            fetchVideos: function (query) {
                query = query || {};
                var self = this;
                var param = {
                    'per_page' : query.per_page || this.per_page,
                    'page' : query.current_page || 1
                };

                var video_resource =  new Resource(API_LIST.NOVICE_VIDEOS, this.$http);
                video_resource.get('',param).then(function (response) {
                    if (response.data.code !==0){
                        throw new Error(response.data.error);
                    }else{
                        this.videos = response.data.videos.data;
                        this.total = response.data.videos.total;
                        this.from = response.data.videos.from;
                        this.to = response.data.videos.to;
                        // this.per_page = Number(response.data.videos.per_page);
                        this.current_page = response.data.videos.current_page;
                    }
                }).catch(function (error) {
                    console.error(error.message)
                });
            },

            /**
             * 去换页码的回调方法
             * @param {number} number
             * @return {undefined}
             */
            currentChange: function (number ) {
                this.fetchVideos({
                    current_page: number
                })
            },

            /**
             * 切换分页size的回调
             * @param {number} size
             * @return {undefined}
             */
            sizeChange: function (size) {
                this.fetchVideos({
                    per_page: size
                })
            }
        },
        mounted: function () {
            this.fetchVideos();
            console.dir(this);
        }
    });
}


 
